package com.itcast.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author HOLO
 * @create 2022-12-27 17:58
 * @discription
 */

@Order(-1)
@Component
public class AuthorizeFilter implements GlobalFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //<editor-fold desc="过滤功能">
     /*   //1.获取请求响应对象
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpResponse response = exchange.getResponse();

        //2.获取参数数据
        MultiValueMap<String, String> params = request.getQueryParams();

        //3.参数 key -> "authorization"
        String authorization = params.getFirst("authorization");

        //4.判断
        if ("admin".equals(authorization)) {
            //放行
            return chain.filter(exchange);
        } else {
            //拦截
            //发送一个权限不足的错误信息给前端
            response.setStatusCode(HttpStatus.UNAUTHORIZED);
            //设置响应结束
            return response.setComplete();
        }*/
        //</editor-fold>


        //默认放行
        return chain.filter(exchange);
    }
}
